package com.zfl;

import java.util.ArrayList;
import java.util.Arrays;

public class ReconstructQueue {

    public int[][] reconstructQueue(int[][] people) {
        int personNum = people.length;
        ArrayList<int[]> res = new ArrayList<>();
        Arrays.sort(people, (a, b) -> b[0] != a[0] ?
                b[0] - a[0] : a[1] - b[1]);
        for (int[] person : people) {
            res.add(person[1], person);
        }
        return res.toArray(new int[personNum][2]);
    }
}
